/*
 *
 * Copyright (C) 2012 Walter Lütgenau
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package offset.nodes.server.data.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import offset.nodes.Constants;
import offset.nodes.server.controller.AuthenticatingAction;
import offset.nodes.server.controller.EditorAttribute;
import offset.nodes.server.dispatch.controller.DispatchAttribute;
import offset.nodes.server.error.model.ExceptionId;
import offset.nodes.server.error.model.LoggedException;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Walter Lütgenau
 */
public class DataAction extends AuthenticatingAction {

    /** Creates a new instance of DocumentationAction */
    public DataAction() {
    }

    public ActionForward process(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        DispatchAttribute dispatchInfo = (DispatchAttribute) request.getAttribute(DispatchAttribute.ATT_DISPATCH);

        if (dispatchInfo.getNode() == null)
            throw new LoggedException(ExceptionId.GENERAL_PATH_INVALID, new Object[]{dispatchInfo.getPath()});

        if (dispatchInfo.getNode().isNodeType(Constants.TYPE_VIRTUAL_PAGE_INSTANCE) && request.getAttribute(EditorAttribute.ATT_EDITOR) != null)
            return mapping.findForward("virtualPageEditor");

        return mapping.findForward("browser");
    }
}
